import sys
sys.path.extend(['.', '..'])
from c_ast_decl import ASTBuilder
builder = ASTBuilder()
ast_for = (builder.for_loop(
        init=builder.expr('=', builder.var('i'), builder.const(0)),  # i=0
        cond=builder.expr('<', builder.var('i'), builder.const(10)), # i<10
        next=builder.expr('+=', builder.var('i'), builder.const(1)) # i+=1
    ).body(
        builder.func_call('printf', [builder.var('i')])
    )._exit_loop().build())
# 验证生成的AST结构
from pycparser import c_generator
print(c_generator.CGenerator().visit(ast_for))